package com.lry.basic.thread;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2020/1/7
 */
public class H2O {
    static int num = 10;
    static int index = 1;
    static volatile boolean f = true;
    public static void main(String[] args) {
        H h = new H();
        O o = new O();
        Thread t1 = new Thread(h);
        Thread t2 = new Thread(o);
        t1.start();
        t2.start();
    }

    static class H implements Runnable{
        @Override
        public void run() {
            while(index<num){
                if(f){
                    System.out.print("HH");
                    index++;
                    f=false;
                }
            }
        }
    }

    static class O implements Runnable{
        @Override
        public void run() {
            while(index<=num){
                if(!f){
                    System.out.print("O");
                    f=true;
                    if(index==num)break;
                }
            }
        }
    }

}
